import type { ConfigEnv, UserConfig } from "vite";
import { defineConfig } from "vite";
import { pluginExposeRenderer } from "./vite.base.config";
import vue from "@vitejs/plugin-vue";
import path from "path";
import ElementPlus from "unplugin-element-plus/vite";

// https://vitejs.dev/config
export default defineConfig((env) => {
  const forgeEnv = env as ConfigEnv<"renderer">;
  const { root, mode, forgeConfigSelf } = forgeEnv;
  const name = forgeConfigSelf.name ?? "";

  return {
    root,
    mode,
    base: "./",
    build: {
      outDir: `.vite/renderer/${name}`,
    },
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"), // 将 @ 别名指向 src 目录
      },
      preserveSymlinks: true,
    },
    css: {
      preprocessorOptions: {
        scss: {
          // @use "@/styles/_variables.scss" as *;
          // @use "@/styles/element/index.scss" as *;
          additionalData: `
            @use "@/styles/index.scss" as *;                      
        `,
        },
      },
    },
    plugins: [
      vue(),
      ElementPlus({
        useSource: true,
      }),
      pluginExposeRenderer(name),
    ],
    clearScreen: false,
  } as UserConfig;
});
